#pragma once
#pragma warning(disable:4996)       // disable checked iterator errors http://msdn.microsoft.com/en-us/library/aa985965(VS.80).aspx 

//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101

#include <Macros.h>
#include <CoVector.h>
#include <CoMatrix.h>
#include <CoCube.h>
#include <ValueHelpers.h>
#include <Settings.h>

#pragma unmanaged 
#include <ql\instruments\makecapfloor.hpp>
#include <boost/smart_ptr/detail/spinlock.hpp>
#pragma managed 

using namespace System;
using namespace QuantLib;
using namespace Cephei;

using namespace Cephei::QL::Times;
using namespace Cephei::QL::Indexes;
using namespace Cephei::QL;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
namespace Cephei { namespace QL { namespace Instruments {
	//////////////////////////////////////////////////////////////////////////////////////////////
	// implementation of IMakeCapFloor
	public ref class CMakeCapFloor : 
            public System::MarshalByRefObject,
            public Cephei::QL::Instruments::IMakeCapFloor
	{
	protected: 
		boost::shared_ptr<QuantLib::MakeCapFloor>* _ppMakeCapFloor;
        boost::detail::spinlock* _pSpinlock;
#ifdef HANDLE
		QuantLib::Handle<QuantLib::MakeCapFloor>* _phMakeCapFloor;
#endif
		Object^ _MakeCapFloorOwner;     // reference to object that manages the storage for this object
	internal:
		CMakeCapFloor (QL::Instruments::CapFloor::TypeEnum capFloorType, Cephei::QL::Times::IPeriod^ capFloorTenor, Cephei::QL::Indexes::IIborIndex^ iborIndex, Microsoft::FSharp::Core::FSharpOption<Double>^ strike, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IPeriod^>^ forwardStart);
        CMakeCapFloor (boost::shared_ptr<QuantLib::MakeCapFloor>& childNative, Object^ owner);
        CMakeCapFloor (QuantLib::MakeCapFloor& childNative, Object^ owner);
        CMakeCapFloor (CMakeCapFloor^ copy);
        CMakeCapFloor (System::Type^ t);
#ifdef STRUCT
        CMakeCapFloor (QuantLib::MakeCapFloor childNative);
#endif       
#ifdef HANDLE
		CMakeCapFloor (QuantLib::Handle<QuantLib::MakeCapFloor>& childNative, Object^ owner);
		CMakeCapFloor (QuantLib::Handle<QuantLib::MakeCapFloor> childNative);
#endif
		virtual ~CMakeCapFloor ();
		!CMakeCapFloor ();

	internal:
		QuantLib::MakeCapFloor& GetReference ();
		boost::shared_ptr<QuantLib::MakeCapFloor>& GetShared ();
		QuantLib::MakeCapFloor* GetPointer ();
        void SetMakeCapFloor (boost::shared_ptr<QuantLib::MakeCapFloor> native)
        {
            if (_ppMakeCapFloor != NULL)
                delete _ppMakeCapFloor;
            _ppMakeCapFloor = new boost::shared_ptr<QuantLib::MakeCapFloor> (native);
            
        }
#ifdef HANDLE
		QuantLib::Handle<QuantLib::MakeCapFloor>& GetHandle ();
#endif
		virtual bool HasNative () ;
		void Lock ()
		{
			if (Cephei::QL::Settings::_ReferenceLocking)
    			_pSpinlock->lock ();
		}
		void Unlock ()
		{
			_pSpinlock->unlock ();
		}
    public:
		virtual Cephei::QL::Instruments::IMakeCapFloor^ WithCalendar (Cephei::QL::Times::ICalendar^ cal) ;
		virtual Cephei::QL::Instruments::IMakeCapFloor^ WithConvention (QL::Times::BusinessDayConventionEnum bdc) ;
		virtual Cephei::QL::Instruments::IMakeCapFloor^ WithDayCount (Cephei::QL::Times::IDayCounter^ dc) ;
		virtual Cephei::QL::Instruments::IMakeCapFloor^ WithEffectiveDate (DateTime effectiveDate, Boolean firstCapletExcluded) ;
		virtual Cephei::QL::Instruments::IMakeCapFloor^ WithEndOfMonth (Microsoft::FSharp::Core::FSharpOption<Boolean>^ flag) ;
		virtual Cephei::QL::Instruments::IMakeCapFloor^ WithFirstDate (DateTime d) ;
		virtual Cephei::QL::Instruments::IMakeCapFloor^ WithNextToLastDate (DateTime d) ;
		virtual Cephei::QL::Instruments::IMakeCapFloor^ WithNominal (Double n) ;
		virtual Cephei::QL::Instruments::IMakeCapFloor^ WithPricingEngine (Cephei::QL::IPricingEngine^ engine) ;
		virtual Cephei::QL::Instruments::IMakeCapFloor^ WithRule (QL::Times::DateGeneration::RuleEnum r) ;
		virtual Cephei::QL::Instruments::IMakeCapFloor^ WithTenor (Cephei::QL::Times::IPeriod^ t) ;
		virtual Cephei::QL::Instruments::IMakeCapFloor^ WithTerminationDateConvention (QL::Times::BusinessDayConventionEnum bdc) ;
		virtual Cephei::QL::Instruments::IMakeCapFloor^ AsOptionlet (Microsoft::FSharp::Core::FSharpOption<Boolean>^ b) ;
    };
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Factory class
	public ref class CMakeCapFloor_Factory : public System::MarshalByRefObject,  public IMakeCapFloor_Factory
	{
	public:
        virtual IMakeCapFloor^ Create (QL::Instruments::CapFloor::TypeEnum capFloorType, Cephei::QL::Times::IPeriod^ capFloorTenor, Cephei::QL::Indexes::IIborIndex^ iborIndex, Microsoft::FSharp::Core::FSharpOption<Double>^ strike, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IPeriod^>^ forwardStart);
    };
   
/*Cephei*/ } /*QL*/ } /*Instruments */}
